package com.lianbang.staff.module.user

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import cn.ubest.mvvmcore.base.BaseActivity
import cn.ubest.mvvmcore.utils.DoubleClickHelper
import cn.ubest.mvvmcore.utils.ToastUtils
import com.lianbang.staff.R
import com.lianbang.staff.databinding.ActivityChangePasswordBinding
import com.lianbang.staff.vm.UserVM
import kotlinx.android.synthetic.main.activity_change_password.*

/**
 * Created by maoqi on 2021/1/15.
 */
class ChangePasswordActivity : BaseActivity<UserVM, ActivityChangePasswordBinding>() {

    companion object{
        @JvmStatic
        fun start(context: Context?) {
            context?.also {
                val starter = Intent(it, ChangePasswordActivity::class.java)
                if (it !is Activity) {
                    starter.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                }
                it.startActivity(starter)
            }
        }
    }

    override fun initLayout(): Int {
        return R.layout.activity_change_password
    }

    override fun initData(intent: Intent) {
    }

    override fun initView() {
        btn_submit.setOnClickListener(object : DoubleClickHelper.OnClickListener() {
            override fun onClicked(view: View?) {
                val oldPwd = et_old_password.text.toString()
                if (oldPwd.trim().isEmpty()) {
                    ToastUtils.toast("旧密码不能为空")
                    return
                }
                val newPwd = et_password.text.toString()
                if (newPwd.trim().isEmpty()) {
                    ToastUtils.toast("新密码不能为空")
                    return
                }
                val confirmNewPwd = et_confirm_password.text.toString()
                if (newPwd.trim() != confirmNewPwd.trim()) {
                    ToastUtils.toast("新密码两次输入不一致")
                    return
                }
                mViewModel.changePassword(oldPwd, newPwd, confirmNewPwd)
            }

        })
    }

    override fun loadData() {
    }

}